﻿using BetterAzureTableStorage;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Linq.Expressions;
using System.Linq;
using Microsoft.WindowsAzure;
using System.Collections.Generic;
using Microsoft.WindowsAzure.StorageClient;

namespace BetterAzureTableStorage.Tests
{
    /// <summary>
    ///This is a test class for TTableStorageQueryProviderTest and is intended
    ///to contain all TTableStorageQueryProviderTest Unit Tests
    ///</summary>
    [TestClass()]
    public class TTableStorageQueryProviderTest
    {
        /////// <summary>
        ///////A test for Execute
        ///////</summary>
        ////[TestMethod()]
        ////public void ExecuteTest()
        ////{
        ////    string tableName = string.Empty;

        ////    TTableStorageQueryProvider target = new TTableStorageQueryProvider(tableName, (t) =>
        ////        {
        ////            return new TTableStorageEngine(
        ////                CloudStorageAccount.DevelopmentStorageAccount.TableEndpoint,
        ////                CloudStorageAccount.DevelopmentStorageAccount.Credentials,
        ////                new List<TTableStorageInfo>()
        ////                {
        ////                    new TTableStorageInfo()
        ////                    {
        ////                        ClassType = typeof(TTestTableEntityDot),
        ////                        TableName = t,
        ////                        PropertyList = new List<TTablePropertyInfo>()
        ////                        {
        ////                            new TTablePropertyInfo(typeof(TTestTableEntityDot).GetProperty("RowKey"),"RowKey")
        ////                        }
        ////                    }
        ////                },
        ////                t,
        ////                RetryPolicies.Retry(3, new TimeSpan(0, 0, 3)),
        ////                null);
        ////        }, null);

        ////    Expression expression = null;

        ////    bool hasExcepted = false;

        ////    expression = Expression.Parameter(typeof(List<int>));

        ////    try
        ////    {
        ////        var actualList = target.Execute(expression);
        ////    }
        ////    catch (Exception e)
        ////    {
        ////        Assert.AreEqual<Type>(typeof(NotImplementedException), e.GetType());
        ////        hasExcepted = true;
        ////    }

        ////    Assert.IsTrue(hasExcepted);
        ////}

        ////[TestMethod]
        ////public void ExecuteGenericTest()
        ////{
        ////    string tableName = "ExecuteGenericTest";

        ////    TTableStorageQueryProvider target = new TTableStorageQueryProvider(tableName, (t) =>
        ////        {
        ////            return new TTableStorageEngine(
        ////                new Uri(@"http://ipv4.fiddler:10002/devstoreaccount1"),
        ////                CloudStorageAccount.DevelopmentStorageAccount.Credentials,
        ////                new List<TTableStorageInfo>()
        ////                {
        ////                    new TTableStorageInfo()
        ////                    {
        ////                        ClassType = typeof(TTestTableEntityDot),
        ////                        TableName = t,
        ////                        PropertyList = new List<TTablePropertyInfo>()
        ////                        {
        ////                            new TTablePropertyInfo(typeof(TTestTableEntityDot).GetProperty("RowKey"),"RowKey")
        ////                        }
        ////                    }
        ////                },
        ////                t,
        ////                RetryPolicies.Retry(3, new TimeSpan(0, 0, 3))
        ////                );
        ////        });

        ////    Expression expression = null;

        ////    object actual;

        ////    bool hasExcepted = false;

        ////    expression = Expression.Parameter(typeof(List<int>));

        ////    try
        ////    {
        ////        actual = target.Execute<TTestTableEntityDot>(expression);
        ////    }
        ////    catch (Exception e)
        ////    {
        ////        Assert.AreEqual<Type>(typeof(TTableStorageException), e.GetType());
        ////        Assert.AreEqual<string>("Non-enumerable operations are not supported.", e.Message);
        ////        hasExcepted = true;
        ////    }

        ////    Assert.IsTrue(hasExcepted);
        ////}

        /// <summary>
        ///A test for CreateQuery
        ///</summary>
        [TestMethod()]
        [ExpectedException(typeof(NotImplementedException))]
        public void CreateQueryTest1()
        {
            TTableStorageInfo tableInfo = new TTableStorageInfo();

            string tableName = string.Empty;
            Func<string, TTableStorageEngine> createTableStorageEngine = null; // TODO: Initialize to an appropriate value
            TTableStorageQueryProvider target = new TTableStorageQueryProvider(new TTableStorageInfo(tableName), createTableStorageEngine, null); // TODO: Initialize to an appropriate value
            Expression expression = null; // TODO: Initialize to an appropriate value
            IQueryable actual;
            actual = target.CreateQuery(expression);
        }
    }
}
